package cn.ctbu.xiaopeng.studentscoremanage.utils;

import cn.ctbu.xiaopeng.studentscoremanage.enums.ResultEnum;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.vo.Result;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.vo.page.ScorePageResult;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.vo.page.TotalRow;
import lombok.extern.slf4j.Slf4j;

/**
 * @author xiaopeng
 * @version 1.0
 */
@Slf4j
public class ScorePageResultUtils {
    public static ScorePageResult success(Object data, Long count, TotalRow totalRow) {
        ScorePageResult result = new ScorePageResult();
        result.setCode(0); //和layui 分页查询的成功响应码对应
        result.setData(data);
        result.setCount(count);

        result.setTotalRow(totalRow);
        result.setMsg("成功");

        // 打印结果
        log.info("返回分页数据成功: {}", result);

        return result;
    }

    public static ScorePageResult success() {
        return success(null, null,null);
    }

    public static Result error(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result error(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        return result;
    }
}
